#![allow(dead_code)]

struct ErrorLrn {}

impl ErrorLrn {
    pub fn hello() {
        println!("Error learning!");
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn enum_error_test() {
        use std::fs;
        use std::io;
        use std::num;

        #[derive(Debug)]
        enum CliError {
            IoError(io::Error),
            ParseError(num::ParseIntError),
        }

        // 参照from_lrn.rs, std::convert::From trait
        impl From<io::Error> for CliError {
            fn from(value: io::Error) -> Self {
                CliError::IoError(value)
            }
        }

        impl From<num::ParseIntError> for CliError {
            fn from(value: num::ParseIntError) -> Self {
                CliError::ParseError(value)
            }
        }

        fn open_and_parse_file(file_name: &str) -> Result<i32, CliError> {
            let contents = fs::read_to_string(file_name)?;
            let num: i32 = contents.trim().parse()?;
            Ok(num)
        }

        let result = open_and_parse_file("test.txt");
        println!("result: {:#?}", result);
    }
}
